<?php

namespace app\home\controller;

use think\exception\HttpResponseException;
use think\facade\Db;
use think\facade\View;
use think\facade\Cache;
use think\facade\Request;
use app\common\controller\AppCommon;
use app\home\model\Config as SystemConfig;
use common\Token;

class Common extends AppCommon
{


    public function __construct(){
        parent::__construct();
		self::systemStatus();//检测状态
    }
	
	public function assign($name,$value){
		View::assign($name, $value);
	}

    public function resJson(...$args){
        throw new HttpResponseException(resJson(...$args));
    }


    /**
     * 读取系统配置
     * @author lijia
     * @date 2018-03-17
     */
    private function readWebsite() {
        $WEBSITE = Cache::get('WEBSITE'); 
        if (!$WEBSITE) {
            $SystemConfig = new SystemConfig();
            $WEBSITE = $SystemConfig->getCfgByModule("SYSTEM_CONFIG");
			Cache::set('WEBSITE',$WEBSITE, 3600);
        }
		View::assign($WEBSITE);
    }	
	
    /**
     * 读取系统SEO配置
     * @author lijia
     * @date 2018-03-17
     */
    private function readSeo() {
        $SITE_SEO = Cache::get('SITE_SEO'); 
        if (!$SITE_SEO) {
            $SystemConfig = new SystemConfig();
            $SITE_SEO = $SystemConfig->getCfgByModule("SITE_SEO");
			Cache::set('SITE_SEO',$SITE_SEO, 3600);
        }
		View::assign($SITE_SEO);
    }		
	
    /**
     * 将所有get参数赋值
     * @author lijia
     * @date 2017-03-29
     */
    private function paramFilter() {
        $request = input('request.'); //get,post,cookies等请求参数
        $param = Request::param(); //获取请求变量
		View::assign($request);
		View::assign($param);
    }	
	
    /**
     * 判断系统状态
     * @author lijia
     * @date 2017-04-18
     */
    static function systemStatus() {
        $config=cache('WEBSITE');
        if ($config['site_status']==2) {
            header('Content-Type:text/html; charset=utf-8');
            exit("<!doctype html><html><head><meta charset=\"utf-8\"><meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no\"><title>系统提示-".ZMCMS_VERSION."</title><style>body{background-color:#444;font-size:14px}h3{font-size:60px;color:#eee;text-align:center;padding-top:30px;font-weight:400}</style></head><body><h3>系统临时关闭，请联系管理员</h3></body></html>");
        }
    }	
	
	
}
